package com.br.aiops.api;

import com.br.aiops.alert.config.Receiver;
import com.br.aiops.alert.config.ReceiverCache;
import com.br.aiops.rule.Rule;
import com.br.aiops.rule.RuleCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 列出所有告警规则
 */
@RestController
@RequestMapping("/api/rule")
public class RuleController {

    @Autowired
    private RuleCache ruleCache;

    @Autowired
    private ReceiverCache receiverCache;

    @GetMapping
    public List<Rule> counters() {
        return ruleCache.getRules();
    }

    @GetMapping("/receiverPerson")
    public Map<String, List<Receiver>> receiversPerson() {
        return receiverCache.getReceiverByPerson();
    }

    @GetMapping("/receiverGroup")
    public Map<String, List<Receiver>> receiversGroup() {
        return receiverCache.getReceiverByGroup();
    }

    @GetMapping("/load")
    public String load() {
        ruleCache.load();
        return "load finish";
    }
}
